/*
 * GContestRoundType.java
 * Created on 24 août 2008
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2008, Jens and Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hockeo.vhbase.data.helper;

/**
 * Enumerates all possible contest round types.
 *
 * @version $Id$
 * @author jjanke
 */
public enum GContestRoundType
{
  // The following constants must be defined in ascending sort order!
  //
  NOT_DEFINED,

  WINNER,

  FINAL,

  SEMI_FINAL,

  QUARTER_FINAL,

  ROUND_OF_16,

  ROUND_OF_32,

  ROUND_INTERMEDIATE,

  ROUND_MAIN,

  ROUND_PRELIMINARY_4,

  ROUND_PRELIMINARY_3,

  ROUND_PRELIMINARY_2,

  ROUND_PRELIMINARY_1,

  QUALIFICATION_1;

  /**
   * Returns the contest round type that matches the given round number in a national cup
   * contest.
   *
   * @param nRoundNum the number of the round for which to determine the round type
   * @param nLastRoundNum the number of the last contest round
   * @return the corresponding round type
   */
  public static GContestRoundType getTypeForNationalCup( int nRoundNum, int nLastRoundNum )
  {
    if ( nRoundNum > nLastRoundNum )
      throw new IllegalArgumentException( "The round number cannot be greater than the number of the last round." );

    int nDiff = nLastRoundNum - nRoundNum;

    switch ( nDiff )
    {
      case 0: return FINAL;
      case 1: return SEMI_FINAL;
      case 2: return QUARTER_FINAL;
      case 3: return ROUND_OF_16;
      case 4: return ROUND_OF_32;
      default:
      {
        switch ( nRoundNum )
        {
          case 1: return ROUND_PRELIMINARY_1;
          case 2: return ROUND_PRELIMINARY_2;
          case 3: return ROUND_PRELIMINARY_3;
          case 4: return ROUND_PRELIMINARY_4;
          default: throw new IllegalStateException( "National cups with more than 9 rounds are not supported." );
        }
      }
    }
  }
}
